// func funcname(形参) -> returntype
// {
//    Statement1
//    Statement2
//    ……
//    Statement N
//    return parameters
// }

func add(a: Int, b: Int) -> Int {
    return a + b
}

let result = add(a: 1, b: 2)
print(result) // 输出: 3


func runoob(site: String) -> String {
    return (site)
}
print(runoob(site: "www.runoob.com"))
// 输出: www.runoob.com

func minMax(array: [Int]) -> (min: Int, max: Int) {
    var currentMin = array[0]
    var currentMax = array[0]
    for value in array[1..<array.count] {
        if value < currentMin {
            currentMin = value
        } else if value > currentMax {
            currentMax = value
        }
    }
    return (currentMin, currentMax)
}

let bounds = minMax(array: [8, -6, 2, 109, 3, 71])
print("最小值为 \(bounds.min) ，最大值为 \(bounds.max)")
//最小值为 -6 ，最大值为 109

//闭包
let addClosure = { (a: Int, b: Int) -> Int in
    return a + b
}

let result2 = addClosure(1, 2)
print(result2) // 输出: 3

//结构体
struct Person {
    var name: String
    var age: Int
}

struct Rectangle {
    var length: Double
    
    init(frombreadth breadth: Double) {
        length = breadth * 10
    }
    
    init(frombre bre: Double) {
        length = bre * 30
    }
    //不提供外部名字
    init(_ area: Double) {
        length = area
    }
}

